//
//  ConnactDetailViewController.swift
//  AESOLAR_IOS
//
//  Created by Mr.Wang on 2019/9/4.
//  Copyright © 2019 Mr.Wang. All rights reserved.
//

import UIKit

class ConnactDetailViewController: BaseUIViewController {
    
    let scrollView = UIScrollView()
    let contentView = UIView()
    
    let model: ConnactModel
    
    init(model: ConnactModel) {
        self.model = model
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = "江苏新源".localized
        
        scrollView.config
            .alwaysBounceVertical(true)
            .addTo(view)
            .makeConstraints { (make) in
                make.edges.equalToSuperview()
        }
        
        contentView.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 1)
        scrollView.addSubview(contentView)
        
        let timeLabel = UILabel().config
            .fontSize(12)
            .textColor(#colorLiteral(red: 0.6901960784, green: 0.6901960784, blue: 0.6901960784, alpha: 1))
            .text(model.createTime)
            .addTo(contentView)
            .makeConstraints { (make) in
                make.left.top.equalTo(15)
        }.view
        
        let contentLabel = UILabel().config
            .font(.systemFont(ofSize: 14, weight: .medium))
            .numberOfLines(0)
            .textColor(#colorLiteral(red: 0.2, green: 0.2, blue: 0.2, alpha: 1))
            .addTo(contentView)
            .makeConstraints { (make) in
                make.left.equalTo(15)
                make.right.equalTo(-15)
                make.top.equalTo(timeLabel.snp.bottom).offset(15)
        }.view
        
        let attributedString = NSMutableAttributedString.init(string: model.replyContent)
        attributedString.setParagraphSpace(5)
        contentLabel.attributedText = attributedString
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        let maxY = contentView.subviews.map{ $0.frame.maxY }.max() ?? 0
        contentView.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: maxY + UIApplication.shared.bottomSafeDistance + 20)
        scrollView.contentSize = contentView.size
    }
    
    override func navigationBarStyle() -> NavigationBarStyle {
        return .baseColor
    }
    
}
